package com.product.mould;

import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class Mould<T>{
    public Integer index = 0;
    public Integer size = 10;
    public Integer total;
    public Integer code = 200;
    public String message = "请求成功";
    public T data;

    /**
     * 返回参数默认
     */
    public Mould() {
        this.index = 0;
        this.size = 10;
        this.total = 0;
        this.code = 200;
        this.message = "请求成功";
        this.data = null;
    }
    /**
     * 返回参数
     * @param index 页数
     * @param size 条数
     * @param total 总数
     * @param code 状态码
     * @param message 状态信息
     * @param data 返回数据
     */
    public Mould(Integer index, Integer size, Integer total, Integer code, String message, T data) {
        this.index = index;
        this.size = size;
        this.total = total;
        this.code = code;
        this.message = message;
        this.data = data;
    }
    /**
     * 返回参数（默认成功模式）
     * @param data 数据
     */
    public Mould(T data) {
        this.data = data;
    }
    /**
     * 返回参数
     * @param code 状态
     * @param message 信息
     * @param data 数据
     */
    public Mould(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    /**
     * 返回参数
     * @param code 状态
     * @param data 数据
     */
    public Mould(Integer code, T data) {
        if(200==code){
            this.message = "请求成功";
        }
        if(400 ==code){
            this.message = "请求体参数不正确";
        }if(401==code){
            this.message = "token 校验失败，非法请求";
        }
        if(500==code){
            this.message = "服务器内部错误";
        }
        this.code = code;
        this.data = data;
    }
    /**
     * 返回分页参数
     * @param data 数据
     */
    public Mould(T data, long total, long current, long size) {
        this.total = (int)total;
        this.index = (int)current;
        this.size = (int)size;
        this.data = data;
    }

    /**
     * 返回分页参数
     * @param data 数据
     * @return this
     */
    public Mould<T> setData(T data, long total, long current, long size) {
        this.total = (int)total;
        this.index = (int)current;
        this.size = (int)size;
        this.data = data;
        return this;
    }
    /**
     * 返回参数
     * @param code 状态
     * @param data 数据
     * @return this
     */
    public Mould<T> setData(int code, T data) {
        if(200==code){
            this.message = "请求成功";
        }
        if(400 ==code){
            this.message = "请求体参数不正确";
        }if(401==code){
            this.message = "token 校验失败，非法请求";
        }
        if(500==code){
            this.message = "服务器内部错误";
        }
        this.code = code;
        this.data = data;
        return this;
    }
    /**
     * 返回参数
     * @param code 状态
     * @param message 信息
     * @param data 数据
     * @return this
     */
    public Mould<T> setData(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
        return this;
    }
    /**
     * 返回参数（默认成功模式）
     * @param data 数据
     * @return this
     */
    public Mould<T> setData(T data) {
        this.data = data;
        return this;
    }

}
